home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / statone / unit1.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  4KB  |  139 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, Stat, unit2, dynary;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     statone1: StatOne;
  12.     listbox2: TListBox;
  13.     memo1: TMemo;
  14.     listbox1: TListBox;
  15.     OpenDialog1: TOpenDialog;
  16.     Label10: TLabel;
  17.     Button3: TButton;
  18.     Button1: TButton;
  19.     Button2: TButton;
  20.     Edit1: TEdit;
  21.     Label1: TLabel;
  22.     Button4: TButton;
  23.     Button5: TButton;
  24.     Label2: TLabel;
  25.     Label3: TLabel;
  26.     procedure Button1Click(Sender: TObject);
  27.     procedure StandardStats;
  28.     procedure Button2Click(Sender: TObject);
  29.     procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  30.     procedure Button3Click(Sender: TObject);
  31.     procedure Button4Click(Sender: TObject);
  32.     procedure Button5Click(Sender: TObject);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. var
  40.   Form1: TForm1;
  41.   ArraySize: integer;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TForm1.Button1Click(Sender: TObject);
  48. begin
  49.     StandardStats;
  50. end;
  51.  
  52. procedure TForm1.StandardStats;
  53. const
  54.   MISSING = 5e-324;
  55. var
  56.     i, j, Point, SetNum: integer;
  57.   RoundMean, RoundMax: LongInt;
  58.   ArrayOK: boolean;
  59.   OrgMean: double;
  60.  
  61. begin
  62.   listbox1.Clear;
  63.      ArraySize := memo1.Lines.Count;
  64.     ArrayOK := statone1.SetSize(ArraySize);
  65.   {if ArrayOk then
  66.       showmessage('Initial array size ' + inttostr(arraysize))
  67.   else
  68.       showmessage('not ok');}
  69.   for i := 1 to ArraySize  do
  70.       statone1[i] := StrToFloat(memo1.Lines[i-1]);
  71.  
  72.   statone1.CalcStat;
  73.  
  74.   for i := 1 to ArraySize do begin
  75.       listbox1.Items.Add(floattostr(statone1[i]));
  76.   end;
  77.  
  78.     listbox2.Clear;
  79.   listbox2.Items.Add('Mean:' + '    ' + FloatToStr(statone1.StatResults.Mean));
  80.   listbox2.Items.Add('Median:' + '    ' + FloatToStr(statone1.StatResults.Median));
  81.   listbox2.Items.Add('GeoMean:' + '    ' + FloatToStr(statone1.StatResults.GeoMean));
  82.   listbox2.Items.Add('HarMean' + '    ' + FloatToStr(statone1.StatResults.HarMean));
  83.   listbox2.Items.Add('IQR:' + '    ' + FloatToStr(statone1.StatResults.IQR));
  84.   listbox2.Items.Add('N:' + '    ' + FloatToStr(statone1.StatResults.N));
  85.   listbox2.Items.Add('Sum:' + '    ' + FloatToStr(statone1.StatResults.Sum));
  86.   listbox2.Items.Add('Variance:' + '    ' + FloatToStr(statone1.StatResults.Variance));
  87.   listbox2.Items.Add('StdDev:' + '    ' + FloatToStr(statone1.StatResults.StdDev));
  88.   listbox2.Items.Add('StdErr:' + '    ' + FloatToStr(statone1.StatResults.StdErr));
  89.   listbox2.Items.Add('Skewness:' + '    ' + FloatToStr(statone1.StatResults.Skewness));
  90.   listbox2.Items.Add('Kurtosis:' + '    ' + FloatToStr(statone1.StatResults.Kurtosis));
  91.  
  92.  
  93. end;
  94.  
  95. procedure TForm1.Button2Click(Sender: TObject);
  96. begin
  97.     StandardStats;
  98.   statone1.Bisquare(StrToInt(Edit1.Text));
  99.   listbox2.Items.Insert(1,'Bisquare:' + '    ' + FloatToStr(statone1.StatResults.Bisquare));
  100.  
  101. end;
  102.  
  103. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
  104. begin
  105.   if ord(key) <> 8 then
  106.   begin
  107.         if length(Edit1.Text) = 1 then
  108.     begin
  109.         key := #0;
  110.     end;
  111.       if (ord(key) < 51) or (ord(key) > 57) then
  112.     begin
  113.         key := #0;
  114.     end;
  115.   end;
  116. end;
  117.  
  118. procedure TForm1.Button3Click(Sender: TObject);
  119. begin
  120.     OpenDialog1.Filter := 'All files [*.*]|*.TXT';
  121.   OpenDialog1.FilterIndex := 0;
  122.     if OpenDialog1.Execute then
  123.   begin
  124.     memo1.Lines.LoadFromfile(OpenDialog1.FileName);
  125.   end;
  126. end;
  127.  
  128. procedure TForm1.Button4Click(Sender: TObject);
  129. begin
  130.     Form2.ShowModal;
  131. end;
  132.  
  133. procedure TForm1.Button5Click(Sender: TObject);
  134. begin
  135.     Close;
  136. end;
  137.  
  138. end.
  139.